import json

from flask import Flask, render_template, Response, request
from methods import *

app = Flask(__name__)


@app.route('/')
def main():
    return render_template("main.html")


@app.route('/get_result1')
def get_result1():
    xAxis, yAxis = result1()
    data = {
        "xAxis": xAxis,
        "yAxis": yAxis
    }
    return Response(json.dumps(data), mimetype='application/json')


@app.route('/get_result2')
def get_result2():
    category, Y, N = result2()
    data = {
        "category": category,
        "Y": Y,
        "N": N
    }
    return Response(json.dumps(data), mimetype='application/json')


@app.route('/get_result3')
def get_result3():
    category, Y = result3()
    data = {
        "category": category,
        "Y": Y
    }
    return Response(json.dumps(data), mimetype='application/json')


@app.route('/get_CF1')
def get_CF1():
    category, related = CF1()
    data = {
        "category": category,
        "related": related
    }
    return Response(json.dumps(data), mimetype='application/json')


@app.route('/get_CF2')
def get_CF2():
    category1 = request.args.get("category1")
    category1, category2, related = CF2(category1)
    data = {
        "category1": category1,
        "category2": category2,
        "related": related
    }
    return Response(json.dumps(data), mimetype='application/json')


if __name__ == '__main__':
    app.run(host="127.0.0.1", port=5000, debug=True)
